package com.ruoyi.rules.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rules.domain.SmartChargingRule;
import com.ruoyi.rules.service.ISmartChargingRuleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 所有收费规则Controller
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/allRules")
public class SmartChargingRuleController extends BaseController
{
    @Autowired
    private ISmartChargingRuleService smartChargingRuleService;

    /**
     * 查询所有收费规则列表
     */
    @RequiresPermissions("rules:allRules:list")
    @GetMapping("/list")
    public TableDataInfo list(SmartChargingRule smartChargingRule)
    {
        startPage();
        List<SmartChargingRule> list = smartChargingRuleService.selectSmartChargingRuleList(smartChargingRule);
        return getDataTable(list);
    }

    /**
     * 导出所有收费规则列表
     */
    @RequiresPermissions("rules:allRules:export")
    @Log(title = "所有收费规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmartChargingRule smartChargingRule)
    {
        List<SmartChargingRule> list = smartChargingRuleService.selectSmartChargingRuleList(smartChargingRule);
        ExcelUtil<SmartChargingRule> util = new ExcelUtil<SmartChargingRule>(SmartChargingRule.class);
        util.exportExcel(response, list, "所有收费规则数据");
    }

    /**
     * 获取所有收费规则详细信息
     */
    @RequiresPermissions("rules:allRules:query")
    @GetMapping(value = "/{scRuleId}")
    public AjaxResult getInfo(@PathVariable("scRuleId") Long scRuleId)
    {
        return success(smartChargingRuleService.selectSmartChargingRuleByScRuleId(scRuleId));
    }

    /**
     * 新增所有收费规则
     */
    @RequiresPermissions("rules:allRules:add")
    @Log(title = "所有收费规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmartChargingRule smartChargingRule)
    {
        return toAjax(smartChargingRuleService.insertSmartChargingRule(smartChargingRule));
    }

    /**
     * 修改所有收费规则
     */
    @RequiresPermissions("rules:allRules:edit")
    @Log(title = "所有收费规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmartChargingRule smartChargingRule)
    {
        return toAjax(smartChargingRuleService.updateSmartChargingRule(smartChargingRule));
    }

    /**
     * 删除所有收费规则
     */
    @RequiresPermissions("rules:allRules:remove")
    @Log(title = "所有收费规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scRuleIds}")
    public AjaxResult remove(@PathVariable Long[] scRuleIds)
    {
        return toAjax(smartChargingRuleService.deleteSmartChargingRuleByScRuleIds(scRuleIds));
    }
}
